{% extends '@admin/index.twig' %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">
      <i aria-hidden="true" class="bi bi-newspaper"></i> {{ msgNews }}
    </h1>
    {% if permissionAddNews == true %}
    <div class="btn-toolbar mb-2 mb-md-0">
      <div class="btn-group mr-2">
        <a href="./news/add">
          <button class="btn btn-outline-success">
            <i aria-hidden="true" class="bi bi-plus"></i> {{ ad_menu_news_add }}
          </button>
        </a>
      </div>
    </div>
    {% endif %}
  </div>

  <div class="row">
    <div class="col-12">
      <table class="table table-hover align-middle">
        <thead class="thead-dark">
        <tr>
          <th>{{ ad_news_headline }}</th>
          <th>{{ ad_news_date }}</th>
          <th colspan="2">&nbsp;</th>
          <th>{{ ad_entry_active }}</th>
        </tr>
        </thead>
        <tbody>
        {% if news|length > 0 %}
          {% for newsItem in news %}
            <tr>
              <td>{{ newsItem.header|escape }}</td>
              <td>{{ newsItem.date|formatDate }}</td>
              <td>
                {% if permissionEditNews == true %}
                <a class="btn btn-primary" href="./news/edit/{{ newsItem.id }}">
                  <span title="{{ ad_news_update }}" class="bi bi-pencil"></span>
                </a>
                {% endif %}
              </td>
              <td>
                {% if permissionDeleteNews == true %}
                <a class="btn btn-danger" data-pmf-newsid="{{ newsItem.id }}" id="deleteNews">
                  <span title="{{ ad_news_delete }}" class="bi bi-trash"></span>
                </a>
                {% endif %}
              </td>
              <td>
                {% if permissionEditNews == true %}
                <input type="checkbox" id="activate" data-pmf-id="{{ newsItem.id }}" data-pmf-csrf-token="{{ csrfToken_activateNews }}"
                       {% if newsItem.active == 'y' %} checked {% endif %} />
                {% endif %}
              </td>
            </tr>
          {% endfor %}
        {% else %}
          <tr>
            <td colspan="4">{{ ad_news_nodata }}</td>
          </tr>
        {% endif %}
        </tbody>
      </table>
    </div>
  </div>
  <div class="modal fade" id="confirmDeleteNewsModal" tabindex="-1" role="dialog" aria-labelledby="confirmDeleteNewsModal"
       aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="confirmDeleteNewsLabel">
            <i aria-hidden="true" class="bi bi-trash"></i> {{ msgDeleteNews }}
          </h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <input type="hidden" name="newsId" id="newsId" value="">
          <input type="hidden" name="pmf-csrf-token" id="pmf-csrf-token-delete" value="{{ csrfToken_deleteNews }}" />
          <div class="row">
            <p>{{ ad_news_del }}</p>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-outline-danger" data-bs-dismiss="modal">
            {{ ad_news_nodelete }}
          </button>
          <button type="button" class="btn btn-success" data-bs-dismiss="modal" id="pmf-delete-news-action">
            {{ ad_news_yesdelete }}
          </button>
        </div>
      </div>
    </div>
  </div>
{% endblock %}
